﻿using MediatR;
using T.Vehicleservice.API.Application.Command.TireUsageRecordCommand;
using T.Vehicleservice.Repository.Interface;

namespace T.Vehicleservice.API.Application.CommandHandlers.TireUsageRecordHandler
{
    public class TireUsageRecordBatchDelCommandHandler : IRequestHandler<TireUsageRecordBatchDelCommand, int>
    {
        private readonly ITireUsageRecordRepository _repository;
        public TireUsageRecordBatchDelCommandHandler(ITireUsageRecordRepository repository)
        {
            _repository = repository;
        }

        public async Task<int> Handle(TireUsageRecordBatchDelCommand request, CancellationToken cancellationToken)
        {
            var list = await _repository.GetAllAsync();
            var tlist=list.Where(x=>request.TireUsageRecordId.Contains(x.TireUsageRecordId.ToString())).ToList();
            foreach (var t in tlist)
            {
                t.IsDeleted = true;
            }
            return await _repository.UpdateRange(tlist);
        }
    }
}
